import {UIMgr} from "../../lib/UIMgr";
import {glConfig} from "../../Config/GLConfig";
import {GCtrl} from "../../lib/util/GCtrl";
import FPJDefine from "../../Game/FPJ/Prefabs/FPJDefine";

const {ccclass, property} = cc._decorator;

@ccclass
export default class DWC_KouLing extends cc.Component {

    @property(cc.Label)
    lbKouLing: cc.Label = null;

    _callback = null;
    _password = "";
    start () {

    }

    init(args){
        this._callback = args[0];
        this._password = "";
        this.initUI();
    }

    initUI(){

        this.lbKouLing.string = "";
    }

    showUI(){
        this.lbKouLing.string = this._password;
    }

    btnClickNumber(e,customEvent){
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
        let num = customEvent;
        if(this._password.length >= 6 ){
            return;
        }
        this._password += num;
        this.showUI();
    }

    btnClickSure(){
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
        //发送命令进入vip
        //直接用口令进入游戏
        let enterVipData = {password:this._password};
        cc.vv.GLUtils.sendRequest("ATTEnterPrivateRoom", enterVipData, (error, data) => {
            if (!data.errorcode) {
                FPJDefine.resetAllData();
                FPJDefine.room_list = data.room_list; //房间列表
                FPJDefine.player_list = data.player_list;// 玩家列表
                FPJDefine.initAllTable();
                FPJDefine.checkVistor()
                this._callback && this._callback();
                UIMgr.close(glConfig.DWC_KouLing_path,GCtrl.UIMgr.closeType.destory);
                this.saveKouLing();
            } else {
                cc.vv.GLUtils.showTips(data.errordes);
            }
        });


    }

    btnClickClear(){
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
        this._password = "";
        this.showUI();
    }
    btnClickClose(){
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
        UIMgr.close(glConfig.DWC_KouLing_path,GCtrl.UIMgr.closeType.destory);
    }

    saveKouLing(){
        cc.sys.localStorage.setItem("KouLing", this._password );
    }
}
